package com.chengqs.test.mvc.web;

import com.chengqs.rapid.client.RapidInvoker;
import com.chengqs.rapid.client.RapidProtocol;
import com.chengqs.rapid.client.RapidService;
import com.chengqs.test.mvc.entity.TestEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <B>主类名称：</B>HelloController<BR>
 * <B>概要说明：</B>enter<BR>
 *
 * @author: chengqs
 * @create: 2025-03-16 20:48:46
 **/
@RestController
@RapidService(patternPath = "/test*", protocol = RapidProtocol.HTTP, serviceId = "hello")
public class HelloController {
    private volatile int count;

    @RapidInvoker(path = "/testGet")
    @GetMapping("/testGet")
    public String testGet() {
        return "testGet";
    }

    @RapidInvoker(path = "/testPost")
    @PostMapping("/testPost")
    public String testPost() {
        count++;
        if (count >= 1e5) {
            System.err.println("<------ chengqs-rapid: ------>");
            count = 0;
        }
        return "chengqs-rapid";
    }

    @RapidInvoker(path = "/testParam")
    @RequestMapping("/testParam")
    public String testParam(@RequestParam String name) {
        count++;
        if (count >= 1e5) {
            System.err.println("<------ testParam收到请求, name:" + name + " ------>");
            count = 0;
        }
        return name;
    }

    @RapidInvoker(path = "/testEntity")
    @RequestMapping("/testEntity")
    public String testEntity(@RequestBody TestEntity testEntity) {
        String result = "testEntity result :" + testEntity.getName() + testEntity.getAge();
        return result;
    }
}
